<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:jsd="http://www.cycle99.com/tools/ecmadoc"
	xmlns:math="http://www.cycle99.com/tools/ecmadoc/transform/math"
	xmlns:help="http://www.cycle99.com/tools/ecmadoc/transform/help"
	xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="jsd math help">

	<xsl:template match="*" mode="header-top">
		<div class="header top">
			<div class="controls">
				<div class="toggle all">
					<label class="expand all">Expand all</label>
					<label class="collapse all">Collapse all</label>
				</div>
				<xsl:if test="count(members/*/*[@visibility = 'private']) != 0">
					<div class="visibility">
						<label class="privates hide">
							Hide private members
						</label>
						<label class="privates show">
							Show private members
						</label>
					</div>
				</xsl:if>
			</div>
			<h1>
				<xsl:apply-templates select="." mode="icon"/>
				<span class="title">
					<span class="name">
						<xsl:apply-templates select="." mode="item-name"/>
					</span>
					<xsl:text> </xsl:text>
					<xsl:apply-templates select="." mode="item-type">
						<xsl:with-param name="showVisibility" select="1"/>
						<xsl:with-param name="capitalize" select="1"/>
					</xsl:apply-templates>
				</span>
			</h1>
			<div class="related">
				<xsl:variable name="project" select="ancestor::project[1]"/>
				<xsl:variable name="class" select="ancestor::class[1]"/>
				<xsl:variable name="namespace" select="ancestor::namespace[1]"/>
				<xsl:if test="$project or $class or $namespace">
					<xsl:if test="$project">
						<div class="link project">
							<a href="{$project/@url}" title="Project">
								<xsl:value-of select="$project/@name"/>
								<xsl:text> </xsl:text>
								<xsl:apply-templates select="$project" mode="item-type">
									<xsl:with-param name="capitalize" select="0"/>
								</xsl:apply-templates>
							</a>
						</div>
					</xsl:if>
					<xsl:if test="$namespace">
						<xsl:if test="$project">
							<div class="link">|</div>
						</xsl:if>
						<div class="link namespace">
							<a href="{$namespace/@url}" title="Namespace">
								<xsl:value-of select="$namespace/@name"/>
								<xsl:text> </xsl:text>
								<xsl:apply-templates select="$namespace" mode="item-type">
									<xsl:with-param name="capitalize" select="0"/>
								</xsl:apply-templates>
							</a>
						</div>
					</xsl:if>
					<xsl:if test="$class">
						<xsl:if test="$project or $namespace">
							<div class="link">|</div>
						</xsl:if>
						<div class="link class">
							<a href="{$class/@url}" title="Class">
								<xsl:value-of select="$class/@name"/>
								<xsl:text> </xsl:text>
								<xsl:apply-templates select="$class" mode="item-type">
									<xsl:with-param name="capitalize" select="0"/>
								</xsl:apply-templates>
							</a>
						</div>
					</xsl:if>
				</xsl:if>
			</div>
		</div>
	</xsl:template>

	<xsl:template match="*" mode="item-name">
		<xsl:value-of select="help:Iif(@visibility = 'static', @staticName, @name)"/>			
	</xsl:template>

	<xsl:template match="*" mode="item-type">
		<xsl:param name="capitalize"/>
		<xsl:param name="showVisibility"/>
		<xsl:if test="@visibility = 'static'">
			<xsl:value-of	select="help:Iif($capitalize = 1, help:ToUpperCaseFirst(@visibility), @visibility)"/>
			<xsl:text> </xsl:text>
		</xsl:if>
		<xsl:value-of select="help:Iif($capitalize = 1, help:ToUpperCaseFirst(name()), name())"/>
	</xsl:template>

	<xsl:template match="*" mode="member-overview">
		<xsl:param name="members" select="*"/>
		<xsl:param name="title" select="help:ToUpperCaseFirst(name())"/>
		<xsl:param name="element" select="help:ToUpperCaseFirst(name($members[1]))"/>

		<xsl:variable name="owner" select="parent::*"/>

		<a name="{name()}" class="anchor"></a>
		<div class="toggleblock mmbr">
			<h4 class="togglehead members">
				<div class="switch"></div>
				<div class="title">
					<xsl:value-of select="$title"/>
				</div>
			</h4>
			<div class="toggledetail">
				<table class="summary" width="100%" cellspacing="1" cellpadding="2">
					<col width="40" align="right"/>
					<col />
					<col />
					<thead>
						<tr>
							<th>
								<xsl:text>&#160;</xsl:text>
							</th>
							<th class="name">
								<xsl:value-of select="$element"/>
							</th>
							<th class="summary">
								Summary
							</th>
						</tr>
					</thead>
					<tbody>
						<xsl:for-each select="$members[@visibility = 'static']">
							<xsl:sort select="@sort" data-type="number" order="ascending" />
							<xsl:sort select="@name" data-type="text" order="ascending" />
							<xsl:apply-templates select="." mode="overview-row"/>
						</xsl:for-each>
						<xsl:for-each select="$members[@visibility != 'static']">
							<xsl:sort select="@sort" data-type="number" order="ascending" />
							<xsl:sort select="@name" data-type="text" order="ascending" />
							<xsl:apply-templates select="." mode="overview-row"/>
						</xsl:for-each>
					</tbody>
				</table>
			</div>
		</div>
	</xsl:template>

	<xsl:template match="*" mode="overview-row">
		<tr>
			<xsl:apply-templates select="." mode="overview-row-attributes"/>
			<td class="iconcell">
				<xsl:apply-templates select="." mode="icon"/>
			</td>
			<td class="name">
				<a href="{@url}" title="{@synopsis}">
					<xsl:value-of select="math:Iif(@visibility = 'static', @staticName, @name)"/>
				</a>
			</td>
			<td class="summary">
				<xsl:apply-templates select="documentation/summary/node()" mode="copy-tree"/>
				<xsl:text>&#160;</xsl:text>
				<xsl:if test="@inheritedFrom">
					<xsl:text>(Inherited from </xsl:text>
					<a href="{@inheritedTypeUrl}"><xsl:value-of select="@inheritedFrom"/></a>
					<xsl:text>.)</xsl:text>
				</xsl:if>
			</td>
		</tr>
	</xsl:template>

	<xsl:template match="*" mode="overview-row-attributes">
		<xsl:attribute name="class">
			<xsl:value-of select="name()"/>
			<xsl:text> </xsl:text>
			<xsl:value-of select="@visibility"/>
			<xsl:if test="@virtual">
				<xsl:text> </xsl:text>
				<xsl:text>virtual</xsl:text>
			</xsl:if>
		</xsl:attribute>
		<xsl:if test="@virtual">
			<xsl:attribute name="title">
				<xsl:text>This object appears in code but its definition could not be found.</xsl:text>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template match="*" mode="icon">
		<xsl:param name="itemtype">
			<xsl:apply-templates select="." mode="item-type"/>
		</xsl:param>
		<xsl:param name="visibility" select="@visibility"/>
		<div class="icon {$itemtype} {$visibility}" title="{help:ToUpperCaseFirst($visibility)} {help:ToUpperCaseFirst($itemtype)}">
			<xsl:if test="$visibility = 'static'">
				<div class="static"></div>
			</xsl:if>
		</div>
	</xsl:template>

	<xsl:template match="*" mode="copy-tree">
		<xsl:element name="{name()}">
			<xsl:apply-templates select="@*" mode="copy-tree"/>
			<xsl:apply-templates select="node()" mode="copy-tree"/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="@*" mode="copy-tree">
		<xsl:attribute name="{name()}">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:template>

	<xsl:template match="text()" mode="copy-tree">
		<xsl:value-of select="." disable-output-escaping="yes"/>
	</xsl:template>

	<xsl:template match="*[documentation/summary]" mode="summary">
		<div class="summary">
			<xsl:apply-templates select="documentation/summary/node()" mode="copy-tree"/>
		</div>
	</xsl:template>

	<xsl:template match="*[documentation/description]" mode="description">
		<div class="toggleblock rmr">
			<h4 class="togglehead">
				<div class="switch"></div>
				<div class="title">
					Remarks
				</div>
			</h4>
			<div class="toggledetail">
				<xsl:apply-templates select="documentation/description/node()" mode="copy-tree"/>
			</div>
		</div>
	</xsl:template>

	<xsl:template match="@*" mode="documentation">
		<xsl:attribute name="{name()}">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:template>

	<xsl:template match="text()" mode="documentation">
		<xsl:value-of select="." disable-output-escaping="yes"/>
	</xsl:template>

	<xsl:template match="*" mode="type-link">
		<xsl:choose>
			<xsl:when test="@typeUrl">
				<a href="{@typeUrl}">
					<xsl:value-of select="@type"/>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="@type"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="*" mode="link">
		<xsl:choose>
			<xsl:when test="@url">
				<a href="{@url}">
					<xsl:value-of select="@name"/>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="@name"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="*" mode="arguments"/>
	<xsl:template match="*" mode="returns"/>
	<xsl:template match="*" mode="examples"/>
	<xsl:template match="*" mode="summary"/>
	<xsl:template match="*" mode="description"/>
	<xsl:template match="*" mode="inheritance"/>
	<xsl:template match="*" mode="synopsis"/>
	<xsl:template match="*" mode="value"/>

	<xsl:template match="property"/>


</xsl:stylesheet>
